package UserModel

// 实体链式调用
type UserModelImpl struct {
	UserId int `gorm:"column:user_id;type:int;primaryKey:autoIncrement" json:"id" form:"id"`
	//  binding:"min=4" 代表最少四个字符
	UserName    string `gorm:"column:user_name;unique;type:varchar(50)" json:"name" form:"name" binding:"min=4"`
	UserPwd     string `gorm:"column:user_pwd;type:varchar(50)" json:"-"`
	UserAddtime string `gorm:"column:user_addtime;type:datetime" json:"addtime"`
}

// gorm自动建表，设置表名，默认使用结构体名称，默认大写处变下划线
func (*UserModelImpl) TableName() string {
	return "go_users"
}

func NewWithID(id int) *UserModelImpl {
	return &UserModelImpl{UserId: id}
}

func New(attrs ...UserModelAttrFunc) *UserModelImpl {
	u := &UserModelImpl{}
	UserModelAttrFuncs(attrs).Apply(u)
	return u
}

func (this *UserModelImpl) Mutate(attrs ...UserModelAttrFunc) *UserModelImpl {
	UserModelAttrFuncs(attrs).Apply(this)
	return this

}
